package com.iweb.controller;

import com.iweb.pojo.User;
import org.springframework.web.bind.annotation.*;

/**
 * 南京艾瑞
 * 作者: jack
 * 时间: 2020-06-28 20:57
 * 描述: UserController
 */
@RestController // 当前类中的方法 默认有 @ResponseBody注解
@RequestMapping("/user")
public class UserController {

    // @PathVariable 将请求url中的参数匹配成方法的参数
    @GetMapping("{id}")
    public User findUserById(@PathVariable("id") Integer id) {
        System.out.println("GET:" + id);
        return new User("jack", 20);
    }


    @DeleteMapping("{id}")
    public User deleteUserById(@PathVariable("id") Integer id) {
        System.out.println("DELETE:" + id);
        return new User("jack", 20);
    }

    @PutMapping("{id}")
    public User updateUserById(
            @PathVariable("id") Integer id,
            @RequestBody User user
    ) {
        System.out.println("PUT:" + id);
        System.out.println(user);
        return new User("jack", 20);
    }

    @PostMapping
    public User addUserInfo(@RequestBody User user) {
        System.out.println(user);
        return user;
    }
}
